import { reqGetAddress, reqGetTradeList } from '@/api'

const state = {
  userAddress: [],
  tradeList: {}
}
const mutations = {
  GETUSERADDRESS(state, userAddress) {
    state.userAddress = userAddress
  },
  GETUSERTRADELIST(state, tradeList) {
    state.tradeList = tradeList
  }
}
const actions = {
  async getUserAddress({ commit }) {
    const res = await reqGetAddress()
    if (res.code == 200) {
      console.log(res)
      commit('GETUSERADDRESS', res.data)
    }
  },
  async getUserTradeList({ commit }) {
    const res = await reqGetTradeList()
    if (res.code == 200) {
      commit('GETUSERTRADELIST', res.data)
    }
  }
}
const getters = {
  detailArrayList(state) {
    return state.tradeList.detailArrayList || []
  }
}

export default {
  state,
  mutations,
  actions,
  getters
}
